//
//  DYZCategoriesController.m
//  发布车源
//
//  Created by xmy on 16/8/19.
//  Copyright © 2016年 xmy. All rights reserved.
//

#import "DYZCategoriesController.h"
#import "DSHTTPClient.h"
#import "UIColor+Addition.h"

static NSString *cellid = @"cellid";

@interface DYZCategoriesController ()

@property(nonatomic,strong)NSArray *loadData;

@end

@implementation DYZCategoriesController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    [self sourcetype];
    
    self.navigationItem.title = @"选择寻车类型";
    
    //注册
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellid];
    self.tableView.rowHeight = 45;
     self.tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
}
//获取车型
- (void)sourcetype{
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    
    [DSHTTPClient postUrlString:@"http://iosapi.itcast.cn/car/sourcetype.json.php" withParam:param withSuccessBlock:^(NSDictionary * data) {
        
        NSDictionary *dict = [data objectForKey:@"data"];
         NSMutableArray *array = [NSMutableArray array];
        
        [array addObject:@"不限"];
        
        NSArray *arr = [dict objectForKey:@"attrList"];
        
        for (NSDictionary *dict1 in arr) {
            
            NSString *str = [dict1 objectForKey:@"attrName"];
            
            [array addObject:str];
            
        }
//        NSLog(@"%@",array);
        self.loadData = array.copy;
        [self.tableView reloadData];
        
        
    } withFailedBlock:^(NSError *error) {
        NSLog(@"%@",error);
        
    } withErrorBlock:^(NSString *message) {
        NSLog(@"%@",message);
    }];
   
   
}
#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.loadData.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid forIndexPath:indexPath];

    cell.textLabel.text = self.loadData[indexPath.row];

    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    
    [cell.textLabel setTextColor:[UIColor colorWithHex:0x333333]];

    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //取消点击效果
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
}

@end
